const { merge } = require('webpack-merge')
const commonConfig = require('./webpack.common')
const CopyWebpackPlgin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') // 压缩CSS
// 合并公共配置
module.exports = merge(commonConfig, { 
  mode: 'production', // 开发模式
  devtool: 'none', //没有源码
  optimization: { // 优化
    // useExports: true, // 没有使用的不会导出
    minimize: true, // 压缩html
    minimizer: [ 
      new OptimizeCSSAssetsPlugin({}) // 压缩CSS
    ]
  },
  module: {
    rules: [
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10*1024,
            esModule: false,
            name: 'img/[name].[hash:8].[ext]'
          }
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10000,
            name: 'fonts/[name].[hash:8].[ext]'
          }
        }
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlgin({
      patterns: [
        { from: 'src/assets/', to: './assets'},
        'public'
      ]
    })
  ]
})